﻿

using System.Windows;
using System.Windows.Media;
using System.ComponentModel;

namespace ImageProcessing.ParameterForms
{
    /// <summary>
    /// Логика взаимодействия для FormScaleConstants.xaml
    /// </summary>
    public partial class FormScaleConstants : Window,INotifyPropertyChanged
    {
        public FormScaleConstants()
        {
            InitializeComponent();
            x_txt.Text = y_txt.Text = "1,0";
        }

        private ImageSource _ScaleImage;
        public ImageSource ScaleImage
        {
            get { return _ScaleImage; }
            set
            {
                _ScaleImage = value;
                OnPropertyChanged("ScaleImage");
            }
        }

        public double XScaleValue
        {
            get
            {
                double value = 0;
                if (x_txt != null) double.TryParse(x_txt.Text, out value);
                if (value != 0) return value;
                else return 1;
            }
        }

        public double YScaleValue
        {
            get
            {
                double value = 0;
                if (y_txt != null) double.TryParse(y_txt.Text, out value);
                if (value != 0) return value;
                else return 1;
            }
        }

        private void Button_OK_Click(object sender, RoutedEventArgs e)
        {
            if (y_txt.Foreground == Brushes.Red || x_txt.Foreground == Brushes.Red)
            {
                MessageBox.Show("Неверный формат значения (введите число больше 0)", "Ошибка формата", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            DialogResult = true;
            Close();
        }

        private void Button_Cancel_Click(object sender, RoutedEventArgs e)
        { Close(); }

        private void ValuesChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            OnPropertyChanged("YScaleValue");
            OnPropertyChanged("XScaleValue");
        }

        #region INotifyPropertyChanged parts
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}